import 'package:flutter_screenutil/screenutil.dart';
import 'package:flutter/material.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/SmsCodeItem.dart';
import 'package:heyangkuaidai/DemonStrateModule/Components/NavigationBar.dart';
import 'package:flutter/gestures.dart';
import 'package:heyangkuaidai/DemonStrateModule/FaceRecPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanEnterModalPage.dart';
import 'package:heyangkuaidai/DemonStrateModule/LoanProtocalPage.dart';

class LoanApplyPage extends StatefulWidget {
  @override
  _LoanApplyPageState createState() => _LoanApplyPageState();
}

class _LoanApplyPageState extends State<LoanApplyPage> {
  String smscode;
  bool isfinsh =false;
  TapGestureRecognizer _tapPressRecognizer;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    smscode ='';
     _tapPressRecognizer = TapGestureRecognizer();
  }
  @override
  void dispose() {
    _tapPressRecognizer.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 375, height: 667, allowFontScaling: true);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Column(
        children: [
          SizedBox(height: MediaQuery.of(context).padding.top,),
          NavigationBar(false, title: "福祥e贷",),
          Container(
              width: ScreenUtil.screenWidth,
              height: ScreenUtil.screenHeight-MediaQuery.of(context).padding.top-ScreenUtil().setWidth(70),
              child: ListView(
                padding: EdgeInsets.only(top: 0),
                children: [
                  infoItem(title:"申请人" ,hitText:"章*闯" ,),
                  infoItem(title:"身份证号", hitText: "430103199308176575",),
                  SizedBox(height: ScreenUtil().setWidth(9),),
                  infoItem(title:"签约机构", hitText: "益阳农商银行",),
                  infoItem(title:"预授信额度", hitText: "100,000.00元",),
                  InkWell(
                    onTap: (){
                       Navigator.push(
                  context,
                  new MaterialPageRoute(
                    builder: (context) => new FaceRecPage(),
                  ),
                ).then((value) {
                        setState(() {
                           isfinsh =true;
                        });
                      });
                    },
                    child:Stack(
                         children: [
                           Container(
                             height: ScreenUtil().setWidth(62),
                             width: ScreenUtil.screenWidth,
                             color: Color(0xffF9FDFF),
                             child: Center(
                               child: Text(isfinsh?"人脸识别已通过":"请先进行人脸识别确认身份",style: TextStyle(fontSize: ScreenUtil().setSp(15),color:Color(0xff5CAFE5)),textAlign: TextAlign.center,),
                             ),
                           ),
                          isfinsh?Container():Positioned(
                              left: ScreenUtil().setWidth(292),
                               top: ScreenUtil().setWidth(23),
                               child: Container(
                                 width: ScreenUtil().setWidth(18),
                                 height: ScreenUtil().setWidth(18),
                                 child: Image.asset("sources/yy/inArrown.png"),
                               )
                           )
                         ],
                    ) 
                  ),
                  SizedBox(height: ScreenUtil().setWidth(9),),
                  infoItem(title:"手机号", hitText: "138473827272",),
                  smsCodeItem(finishCallback: (text){
                    smscode =text;
                  },),
                  SizedBox(height: ScreenUtil().setWidth(9),),
                  Container(
                    padding: EdgeInsets.only(left: 20,right: 20),
                    width: ScreenUtil().setWidth(347),
                    height: ScreenUtil().setWidth(50),
                    child:Text.rich(
                        TextSpan(
                            children: [
                              WidgetSpan(
                                  child:InkWell(
                                    onTap: (){},
                                    child:Container(
                                      width: ScreenUtil().setWidth(15),
                                      height: ScreenUtil().setWidth(15),
                                      child:Image.asset("sources/yy/check.png") ,
                                    ),
                                  )
                              ),
                              TextSpan(text: "    我已阅读并同意",style: TextStyle(fontSize: ScreenUtil().setSp(14),color: Colors.black)),
                              TextSpan(text: "《综合信息授权书》",style: TextStyle(fontSize: ScreenUtil().setWidth(14),color: Color(0xff4770F7)),recognizer:
                              _tapPressRecognizer..onTap =(){
                                Navigator.push(
                                  context,
                                  new MaterialPageRoute(
                                    builder: (context) => new LoanProtocalPage(),
                                  ),
                                );
                              }
                              ),
                              TextSpan(text: "《个人征信授权书》",style: TextStyle(fontSize: ScreenUtil().setWidth(14),color: Color(0xff4770F7)),recognizer:
                              _tapPressRecognizer..onTap =(){
                                Navigator.push(
                                  context,
                                  new MaterialPageRoute(
                                    builder: (context) => new LoanProtocalPage(),
                                  ),
                                );
                              }
                              )
                            ]
                        )
                    ),
                  ),
                  SizedBox(
                    height: ScreenUtil().setWidth(16),
                  ),
                  Column(
                    children: [
                      InkWell(
                        onTap: (){
                          if(smscode.isEmpty){
                            return;
                          }
                          Navigator.push(
                            context,
                            new MaterialPageRoute(
                              builder: (context) => new LoanEnterModalPage(),
                            ),
                          );
                        },
                        child: Container(
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4),
                              color:Color(0xff41A5EE),
                            ),
                            width: ScreenUtil().setWidth(347),
                            height: ScreenUtil().setWidth(44),
                            child:Center(
                              child: Text("确认并申请",style: TextStyle(fontSize: ScreenUtil().setSp(17),color: Colors.white),textAlign: TextAlign.center,),
                            )
                        ) ,
                      ),
                      SizedBox(height: ScreenUtil().setWidth(20),),
                      InkWell(
                        onTap: (){
                          Navigator.pop(context);
                        },
                        child: Container(
                            decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(4),
                                color:Color(0xffFFFFFF),
                                border: Border.all(
                                    color: Color(0xff41A5EE),
                                    width: 1,
                                    style: BorderStyle.solid
                                )
                            ),
                            width: ScreenUtil().setWidth(347),
                            height: ScreenUtil().setWidth(44),
                            child:Center(
                              child: Text("返回",style: TextStyle(fontSize: ScreenUtil().setSp(17),color: Color(0xff41A5EE)),textAlign: TextAlign.center,),
                            )
                        ) ,
                      )
                    ],
                  )
                ],
              )
          ) ,

          ],
      ),
    );
  }
}

//第一类item
class infoItem extends StatefulWidget {
  String title;
  String hitText;
  infoItem({this.title,this.hitText,Key key}) : super(key: key);
  @override
  _infoItemState createState() => _infoItemState();
}

class _infoItemState extends State<infoItem> {

  @override
  Widget build(BuildContext context) {
    return Container(
        color:Colors.white,
        width: ScreenUtil.screenWidth,
        height: ScreenUtil().setWidth(50),
        child:Column(
          children: [
            Container(height: ScreenUtil().setWidth(49),
              child:Row(
                children: [
                  SizedBox(width:ScreenUtil().setWidth(14) ,),
                  Container(
                    width: ScreenUtil().setWidth(80),
                    child:Text(widget.title,style: TextStyle(fontSize: ScreenUtil().setSp(15),color:Color(0xff888888)),textAlign: TextAlign.left,),
                  ),
                  SizedBox(width:ScreenUtil().setWidth(10) ,),
                  Container(
                    width: ScreenUtil().setWidth(200),
                    child:Text(widget.hitText,style: TextStyle(fontSize: ScreenUtil().setSp(15),color:Color(0xff333333)),textAlign: TextAlign.left,),
                  ),
                ],
              ),),
            Container(height: ScreenUtil().setWidth(0.5),width: ScreenUtil.screenWidth,color: Color(0xffD8D8D8),),
          ],
        )
    );
  }
}